package cn.car.exception;

import cn.car.domains.enums.StatusCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serial;
import java.text.MessageFormat;

@EqualsAndHashCode(callSuper = true)
@Data
public class CarAccessControlException extends RuntimeException {
    @Serial
    private static final long serialVersionUID = -1L;
    protected String message;
    protected String defineCode;

    public static final CarAccessControlException DATE_NOT_EXIST = new CarAccessControlException(StatusCode.DATE_NOT_EXIST);

    public static final CarAccessControlException PASSWORD_ERROR = new CarAccessControlException(StatusCode.PASSWORD_ERROR);

    public static final CarAccessControlException USER_EXIST = new CarAccessControlException(StatusCode.USER_EXIST);

    public static final CarAccessControlException DATE_EXIST = new CarAccessControlException(StatusCode.DATE_EXIST);

    public static final CarAccessControlException FILE_PATH_ERROR = new CarAccessControlException(StatusCode.FILE_PATH_ERROR);

    public static final CarAccessControlException FILE_UPLOAD_ERROR = new CarAccessControlException(StatusCode.FILE_UPLOAD_ERROR);

    public static final CarAccessControlException FILE_NOT_FOUND = new CarAccessControlException(StatusCode.FILE_NOT_FOUND);

    public static final CarAccessControlException SYSTEM_ERROR = new CarAccessControlException(StatusCode.SYSTEM_ERROR);

    public static final CarAccessControlException PARAMS_ERROR = new CarAccessControlException(StatusCode.PARAMS_ERROR);

    public static final CarAccessControlException SEND_MSG_ERROR = new CarAccessControlException(StatusCode.SEND_MSG_ERROR);

    public static final CarAccessControlException DATA_NOT_EXIST = new CarAccessControlException(StatusCode.DATE_NOT_EXIST);

    public static final CarAccessControlException REDIS_ERROR = new CarAccessControlException(StatusCode.DATE_NOT_EXIST);

    public static final CarAccessControlException USER_NOT_EXIST = new CarAccessControlException(StatusCode.USER_NOT_EXIST);

    public static final CarAccessControlException PASSWORD_INCORRECT = new CarAccessControlException(StatusCode.PASSWORD_INCORRECT);

    public static final CarAccessControlException DELETE_NOT_EXIST = new CarAccessControlException(StatusCode.DELETE_NOT_EXIST);

    public static final CarAccessControlException UPDATE_NOT_EXIST = new CarAccessControlException(StatusCode.UPDATE_NOT_EXIST);

    public static final CarAccessControlException INSERT_ERROR = new CarAccessControlException(StatusCode.INSERT_ERROR);

    public static final CarAccessControlException IMPL_NOT_EXIST = new CarAccessControlException(StatusCode.IMPL_NOT_EXIST);

    public static final CarAccessControlException LEDGER_RECORD_ERROR = new CarAccessControlException(StatusCode.LEDGER_RECORD_ERROR);




    public CarAccessControlException(String defineCode, String message, Object... args) {
        this.defineCode = defineCode;
        this.setMessage(message, args);
    }


    public CarAccessControlException(StatusCode statusCode, String message, Object... args) {
        this(statusCode.getCode(), message, args);
    }

    public CarAccessControlException(StatusCode statusCode) {
        this.defineCode = statusCode.getCode();
        this.message = statusCode.getMessage();
    }

    public void setMessage(String message, Object... args) {
        this.message = MessageFormat.format(message, args);
    }

    public CarAccessControlException newInstance(String message, Object... args) {
        return new CarAccessControlException(defineCode, message, args);
    }
}
